package cz.muni.fi.hauntedhouses.entity;

import cz.muni.fi.hauntedhouses.type.Cas;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 *
 * @author Jan Volmut, 324836
 */
@Entity
public class Ghost implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(columnDefinition="VARCHAR(50)")
    private String name;
    
    private Cas hauntingFrom;
    
    private Cas hauntingTo;
    
    private String description;
    
    @JoinColumn(nullable = true)
    @ManyToOne
    private Skill skill;
    
    @JoinColumn(nullable = true)
    @ManyToOne
    private House house;
    
    /**
     * The power represents how strong is the ghost. It is modifier of haunting
     * or how scared person is when see the ghost. Values should be positive
     * and correspond with the idea (0.5 - weak one, 1.7 - more scare,
     * 85.4 - The boss from the entire hell)
     */
    private Float power;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public Cas getHauntingFrom() {
        return hauntingFrom;
    }

    public void setHauntingFrom(Cas HauntingFrom) {
        this.hauntingFrom = HauntingFrom;
    }

    public Cas getHauntingTo() {
        return hauntingTo;
    }

    public void setHauntingTo(Cas HauntingTo) {
        this.hauntingTo = HauntingTo;
    }
    

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Float getPower() {
        return power;
    }

    public void setPower(Float power) {
        if(power < 0) {
            throw new IllegalArgumentException(
                    "The value of power have to be positive"
                    );
        }
        this.power = power;
    }
    
    public Skill getSkill() {
        return skill;
    }

    public void setSkill(Skill skill) {
        this.skill = skill;
    }
    
    public House getHouse() {
        return house;
    }

    public void setHouse(House house) {
        this.house = house;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Ghost)) {
            return false;
        }
        Ghost other = (Ghost) object;
        if (this.id == null || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Ghost[Name: "+this.getName()+" "+"Haunting from: "
                + this.getHauntingFrom()+" "+"Haunting to: "
                + this.getHauntingTo()+"]";
    }
    
}
